﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace davejk.Minecraft.ServerWrapper.Utils
{
    public static class CheckForJava
    {

        public static bool JavaWorks()
        {
            Process JavaProcess = new Process();
            JavaProcess.StartInfo = new ProcessStartInfo { FileName = "java", UseShellExecute = false, CreateNoWindow = true };
            try
            {
                JavaProcess.Start();
            }
            catch (Exception ex)
            {
                if (MessageBox.Show("Java is not installed or is not in your user or system PATH.\n\n" +
                    "The Minecraft server cannot run without Java. Would you like to download it now?",
                    "Java", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
                    == DialogResult.Yes)
                {
                    Process.Start("http://java.com/en/download/manual.jsp");
                }
                return false;
            }
            return true;
        }

    }
}
